package org.mstrsoft.intergrator.view.components.common;

import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.JXLabel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: 02.06.2009
 * Time: 11:18:52
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractNode extends JXPanel implements MouseListener {
    JComponent component=null;
    CardLayout layout=new CardLayout();
    JXLabel label=new JXLabel();
    String text;
    boolean state=false;

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
        label.setText(text);
    }


    public AbstractNode(String text) {
        super();
        label.setText(text);    
        setLayout(layout);
        layout.addLayoutComponent(label,"label");
    }

     public void setEditableState(boolean state)
     {
         if (state)
             layout.show(this,"front");
         else
             layout.show(this,"label");

     }

    public JComponent getAditionalComponent() {
        return component;  
    }

    public void setAditionalComponent(JComponent component) {
        if (component==null)
        {
            this.component=component;
            layout.addLayoutComponent(label,"front");
        }
    }

        public void mouseClicked(MouseEvent e)
        {
            state=!state;
            setEditableState(state);
        }
    public void mousePressed(MouseEvent e){};

    /**
     * Invoked when a mouse button has been released on a component.
     */
    public void mouseReleased(MouseEvent e){};

    /**
     * Invoked when the mouse enters a component.
     */
    public void mouseEntered(MouseEvent e){};

    /**
     * Invoked when the mouse exits a component.
     */
    public void mouseExited(MouseEvent e){};
}
